package com.quanyue.music.template.service.impl;

import com.quanyue.music.domain.entity.FormId;
import com.quanyue.music.template.mapper.TemplateMapper;
import com.quanyue.music.template.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class TemplateServiceImpl implements TemplateService {
    @Autowired
    private TemplateMapper templateMapper;

    @Override
    public void addFormId(FormId formId, String userId) {
        formId.setUserId(userId);
        formId.setCreateTime(LocalDateTime.now());
        formId.setExpireTime(LocalDateTime.now().plusHours(167));
        templateMapper.insert(formId);
    }

    @Override
    public List <FormId> getFormIdList() {
        return templateMapper.findAll();
    }

    @Override
    public List <FormId> getFormId(String userId) {
        return templateMapper.findByUserId(userId);
    }

    @Override
    public Integer findFormIdCount(String userId, LocalDate localDate) {
        return templateMapper.findByUserIdAndDate(userId, localDate).size();
    }

    @Override
    public void delOne(String id) {
        templateMapper.deleteOne(id);
    }

    @Override
    public void delList(List <String> ids) {
        templateMapper.deleteAll(ids);
    }
}
